home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Arsenal / OS2 Arsenal v1.0 (Disc 1)(Arsenal Computer).ISO / os2_inet / tcp20c2.exe / BASEC2.ZIP / BIN / atdial.cmd < prev    next >
Encoding:
Text File  |  1994-05-18  |  8.9 KB  |  220 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                OS/2 2.0 SLIP Driver for IBM TCP/IP version 2.0           */
  4. /*                                                                          */
  5. /*                               ATDIAL.CMD                                 */
  6. /*                                                                          */
  7. /*            ..................................................            */
  8. /*                                                                          */
  9. /* Sample attachment script for dialing into a system w/o password          */
  10. /* protection.  This script should be specified using the "attachcmd" and   */
  11. /* "attachparm" elements in configuration file.                             */
  12. /*                                                                          */
  13. /*              interface sl0 {                                             */
  14. /*                 ipaddress  = 222.222.222.222                             */
  15. /*                 ipdest     = 222.222.222.222                             */
  16. /*                 attachcmd  = atdial.cmd                                  */
  17. /*                 attachparm = "dialcmd"                                   */
  18. /*              }                                                           */
  19. /*                                                                          */
  20. /*            - - - - - - - - - - - - - - - - - - - - - - - - -             */
  21. /*                                                                          */
  22. /* When the script runs, it is automatically passed the interface name for  */
  23. /* the interface it is running on as the first argument, the ipaddress      */
  24. /* and ipdest addresses for the host and peer as the second and third       */
  25. /* arguments and the user arguments from the configuration file as the      */
  26. /* last arguments.  The attachparm command should look like:                */
  27. /*               attachparm="com1 57600 atdt999,9999"                       */
  28. /*                                                                          */
  29. /*--------------------------------------------------------------------------*/
  30.  
  31. parse arg interface , ipaddress, ipdest, comport baud dialcmd
  32.  
  33. /*--------------------------------------------------------------------------*/
  34. /*                   Initialization and Main Script Code                    */
  35. /*--------------------------------------------------------------------------*/
  36.  
  37. /* Set some definitions for easier COM strings */
  38. cr='0d'x
  39. crlf='0d0a'x
  40. timeout = 0
  41.  
  42. say ''
  43. say 'ATDIAL - SL/IP Dialer Script ',
  44.     '(interface' interface')'
  45.  
  46. 'mode ' comport baud ',n,8,1,buffer=on'
  47.  
  48. /* Prompt for missing information */
  49. if dialcmd = '' then do
  50.    call charout , 'Dial Command: '
  51.    parse pull dialcmd
  52. end
  53.  
  54. /* Flush any stuff left over from previous COM activity */
  55. call flush_receive
  56.  
  57. /* Dial the remote server */
  58. call lineout , 'Reset modem...'
  59. call send 'ATZ' || cr
  60. call waitfor 'OK', 5 ; call flush_receive 'echo'
  61.  if RC = 1 then do
  62.     call lineout , 'Modem not resetting... Trying again'
  63.     call send '+++'
  64.     call waitfor 'OK'
  65.     call send 'ATHZ' || cr
  66.     call waitfor 'OK', 3
  67.   end
  68.  
  69. /* The following turns on RTS/CTS flow control on some AT command set modems */
  70. /* Consult your manual if RTS/CTS is not set on by default */
  71. /* call send 'AT\Q3' || cr */
  72. /* call waitfor 'OK'; call flush_receive 'echo' */
  73.  
  74. /* Wait for connection */
  75. call lineout , 'Now Dialing...'
  76. call send dialcmd || cr
  77. call waitfor 'CONNECT', 40 ; call waitfor crlf , 2
  78.  if RC = 1 then do
  79.     call lineout , ' Unable to connect exit from ATDIAL '
  80.     exit(2)
  81.   end
  82.   else do
  83.     /* Flush anything else */
  84.     call flush_receive 'echo'
  85.  
  86.     /* Now configure this host for the appropriate address, */
  87.     /*
  88.      *  Comment or Uncomment as approriate for your configuration 
  89.      */
  90.  
  91.     'ifconfig ' interface  ipaddress ipdest ' netmask 255.255.255.0'
  92.  
  93.     /* 'route -f add default' ipdest '1' */
  94.     /* All done */
  95.     exit 0
  96.   end
  97.  
  98. /*--------------------------------------------------------------------------*/
  99. /*                            send ( sendstring)                            */
  100. /*..........................................................................*/
  101. /*                                                                          */
  102. /* Routine to send a character string off to the modem.                     */
  103. /*                                                                          */
  104. /*--------------------------------------------------------------------------*/
  105.  
  106. send:
  107.  
  108.    parse arg sendstring
  109.    call slip_com_output interface , sendstring
  110.  
  111.    return
  112.  
  113. /*--------------------------------------------------------------------------*/
  114. /*                    waitfor ( waitstring , [timeout] )                    */
  115. /*..........................................................................*/
  116. /*                                                                          */
  117. /* Waits for the supplied string to show up in the COM input.  All input    */
  118. /* from the time this function is called until the string shows up in the   */
  119. /* input is accumulated in the "waitfor_buffer" variable.                   */
  120. /*                                                                          */
  121. /* If timeout is specified, it says how long to wait if data stops showing  */
  122. /* up on the COM port (in seconds).                                                         */
  123. /*                                                                          */
  124. /*--------------------------------------------------------------------------*/
  125.  
  126. waitfor:
  127.  
  128.    parse arg waitstring , timeout
  129.  
  130.    if timeout = '' then
  131.      timeout = 5000    /* L O N G   delay if not specified */
  132.    waitfor_buffer = '' ; done = -1; curpos = 1
  133.    ORI_TIME=TIME('E')
  134.  
  135.    if (remain_buffer = 'REMAIN_BUFFER') then do
  136.       remain_buffer = ''
  137.    end
  138.  
  139.    do while (done = -1)
  140.       if (remain_buffer \= '') then do
  141.          line = remain_buffer
  142.          remain_buffer = ''
  143.        end
  144.        else do
  145.          line = slip_com_input(interface,,10)
  146.       end
  147.       waitfor_buffer = waitfor_buffer || line
  148.       index = pos(waitstring,waitfor_buffer)
  149.       if (index > 0) then do
  150.          remain_buffer = substr(waitfor_buffer,index+length(waitstring))
  151.          waitfor_buffer = delstr(waitfor_buffer,index+length(waitstring))
  152.          done = 0
  153.       end
  154.       call charout , substr(waitfor_buffer,curpos)
  155.       curpos = length(waitfor_buffer)+1
  156.       if ((done \= 0) & (TIME('E')>timeout)) then do
  157.         call lineout , ' WAITFOR: timed out '
  158.         done = 1
  159.        end
  160.    end
  161.    timeout=0
  162.    RC=done
  163.  return RC
  164.  
  165.  
  166. /*--------------------------------------------------------------------------*/
  167. /*                               readpass ()                                */
  168. /*..........................................................................*/
  169. /*                                                                          */
  170. /* Routine used to read a password from the user without echoing the        */
  171. /* password to the screen.                                                  */
  172. /*                                                                          */
  173. /*--------------------------------------------------------------------------*/
  174.  
  175. readpass:
  176.  
  177.   answer = ''
  178.   do until key = cr
  179.     key = slip_getch()
  180.     if key \= cr then do
  181.       answer = answer || key
  182.     end
  183.   end
  184.   say ''
  185.   return answer
  186.  
  187.  
  188. /*--------------------------------------------------------------------------*/
  189. /*                             flush_receive ()                             */
  190. /*..........................................................................*/
  191. /*                                                                          */
  192. /* Routine to flush any pending characters to be read from the COM port.    */
  193. /* Reads everything it can until nothing new shows up for 100ms, at which   */
  194. /* point it returns.                                                        */
  195. /*                                                                          */
  196. /* The optional echo argument, if 1, says to echo flushed information.      */
  197. /*                                                                          */
  198. /*--------------------------------------------------------------------------*/
  199.  
  200. flush_receive:
  201.  
  202.    parse arg echo
  203.  
  204.    /* If echoing the flush - take care of waitfor remaining buffer */
  205.    if (echo \= '') & (length(remain_buffer) > 0) then do
  206.       call charout , remain_buffer
  207.       remain_buffer = ''
  208.    end
  209.  
  210.    /* Eat anything left in the modem or COM buffers */
  211.    /* Stop when nothing new appears for 100ms.      */
  212.  
  213.    do until line = ''
  214.      line = slip_com_input(interface,,100)
  215.      if echo \= '' then
  216.         call charout , line
  217.    end
  218.  
  219.    return
  220.